import requests

url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604973522&di=891f4cc72867958bb004279e6f880d18&imgtype=jpg&er=1&src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn00%2F124%2Fw446h478%2F20181020%2F6289-hmrasqs7500511.png'

# 将stream设置为True  执行这一行是不会直接进行下载
r = requests.get(url=url, stream=True)

# 获取数据的总大小
body_len = int(r.headers.get('Content-Length'))
print('图片长度为：%d' % body_len)

a = 0
with open('girl2.jpg', 'wb') as img:
    for img_enc in r.iter_content(chunk_size=500):
        a = img.write(img_enc)

        #计算下载进度
        print('下载进度为：%2.2f %%' % (a * 100 / body_len))
